home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Examples / Helpfile / TCPSend.au3 < prev    next >
Text File  |  2007-09-08  |  2KB  |  50 lines

  1. ;CLIENT! Start Me after starting the SERVER!!!!!!!!!!!!!!!
  2. ; see TCPRecv example
  3. #include <GUIConstants.au3>
  4.  
  5. ; Start The TCP Services
  6. ;==============================================
  7. TCPStartUp()
  8.  
  9. ; Set Some reusable info
  10. ;--------------------------
  11. Dim $szServerPC = @ComputerName
  12. ; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address
  13. Dim $szIPADDRESS = TCPNameToIP($szServerPC)
  14. Dim $nPORT = 33891
  15.  
  16.  
  17. ; Initialize a variable to represent a connection
  18. ;==============================================
  19. Dim $ConnectedSocket = -1
  20.  
  21.  
  22. ;Attempt to connect to SERVER at its IP and PORT 33891
  23. ;=======================================================
  24. $ConnectedSocket = TCPConnect($szIPADDRESS,$nPORT)
  25.  
  26.  
  27. Dim $szData
  28.  
  29. ; If there is an error... show it
  30. If @error Then
  31.     MsgBox(4112,"Error","TCPConnect failed with WSA error: " & @error)
  32. ; If there is no error loop an inputbox for data
  33. ;   to send to the SERVER.
  34. Else
  35. ;Loop forever asking for data to send to the SERVER
  36.     While 1
  37.     ; InputBox for data to transmit
  38.         $szData = InputBox("Data for Server",@LF & @LF & "Enter data to transmit to the SERVER:")
  39.         
  40.     ; If they cancel the InputBox or leave it blank we exit our forever loop
  41.         If @error Or $szData = "" Then ExitLoop
  42.         
  43.     ; We should have data in $szData... lets attempt to send it through our connected socket.
  44.         TCPSend($ConnectedSocket,$szData)
  45.         
  46.     ; If the send failed with @error then the socket has disconnected
  47.     ;----------------------------------------------------------------
  48.         If @error Then ExitLoop
  49.     WEnd
  50. EndIf